package com.iotechn.unimall.data.dto.excel;

import lombok.Data;

import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.List;

/**
 * 表格导出汇总
 *
 * @author kyms
 * @date 2020-08-16 17:48
 */
@Data
public class SummaryTotalDTO implements Serializable {

    List<SkuTotalSummaryDTO> skuTotalSummaryDTOS;
    private Float startStock;
    private Float startStockPrice;
    private Float endStock;
    private Float endStockPrice;
    private Float inNum;
    private Float inNumPrice;
    private Float outNum;
    private Float outNumPrice;
    private Float commonLossNum;
    private Float commonLossNumPrice;
    private Float tasteLossNum;
    private Float tasteLossNumPrice;
    private Float allotInNum;
    private Float allotInNumPrice;
    private Float allotOutNum;
    private Float allotOutNumPrice;
    private Float onlineNum;
    private Float onlineNumPrice;
    private Float offlineNum;
    private Float offlineNumPrice;
    private Float returnNum;
    private Float returnNumPrice;
    private Float returnSupplierNum;
    private Float returnSupplierNumPrice;
    private Float stockCheckAddNum;
    private Float stockCheckAddNumPrice;
    private Float stockCheckSubNum;
    private Float stockCheckSubNumPrice;

    public SummaryTotalDTO(List<SkuTotalSummaryDTO> skuTotalSummaryDTOS) {
        this.skuTotalSummaryDTOS = skuTotalSummaryDTOS;
    }

    public SummaryTotalDTO() {
    }


    public Float getStartStock() {
        if (this.skuTotalSummaryDTOS == null || this.skuTotalSummaryDTOS.size() == 0) {
            return 0f;
        }
        Float sum = this.skuTotalSummaryDTOS.stream().map(item -> {
            if (item.getStartStock() == null) {
                return 0f;
            }
            return item.getStartStock().getNum();
        }).reduce(0f, Float::sum);
        DecimalFormat decimalFormat = new DecimalFormat(".000");
        String total = decimalFormat.format(sum);
        return Float.valueOf(total);
    }

    public Float getEndStock() {
        if (this.skuTotalSummaryDTOS == null || this.skuTotalSummaryDTOS.size() == 0) {
            return 0f;
        }
        Float sum = this.skuTotalSummaryDTOS.stream().map(item -> {
            if (item.getEndStock() == null) {
                return 0f;
            }
            return item.getEndStock().getNum();
        }).reduce(0f, Float::sum);
        DecimalFormat decimalFormat = new DecimalFormat(".000");
        String total = decimalFormat.format(sum);
        return Float.valueOf(total);
    }

    public Float getInNum() {
        if (this.skuTotalSummaryDTOS == null || this.skuTotalSummaryDTOS.size() == 0) {
            return 0f;
        }
        Float sum = this.skuTotalSummaryDTOS.stream().map(item -> {
            if (item.getPurchaseStock() == null) {
                return 0f;
            }
            return item.getPurchaseStock().getNum();
        }).reduce(0f, Float::sum);
        DecimalFormat decimalFormat = new DecimalFormat(".000");
        String total = decimalFormat.format(sum);
        return Float.valueOf(total);
    }

    public Float getOutNum() {
        if (this.skuTotalSummaryDTOS == null || this.skuTotalSummaryDTOS.size() == 0) {
            return 0f;
        }
        Float sum = this.skuTotalSummaryDTOS.stream().map(item -> {
            if (item.getSalesSendStock() == null) {
                return 0f;
            }
            return item.getSalesSendStock().getNum();
        }).reduce(0f, Float::sum);
        DecimalFormat decimalFormat = new DecimalFormat(".000");
        String total = decimalFormat.format(sum);
        return Float.valueOf(total);
    }

    public Float getCommonLossNum() {
        if (this.skuTotalSummaryDTOS == null || this.skuTotalSummaryDTOS.size() == 0) {
            return 0f;
        }
        Float sum = this.skuTotalSummaryDTOS.stream().map(item -> {
            if (item.getCommonLossStock() == null) {
                return 0f;
            }
            return item.getCommonLossStock().getNum();
        }).reduce(0f, Float::sum);
        DecimalFormat decimalFormat = new DecimalFormat(".000");
        String total = decimalFormat.format(sum);
        return Float.valueOf(total);
    }

    public Float getTasteLossNum() {
        if (this.skuTotalSummaryDTOS == null || this.skuTotalSummaryDTOS.size() == 0) {
            return 0f;
        }
        Float sum = this.skuTotalSummaryDTOS.stream().map(item -> {
            if (item.getTasteLossStock() == null) {
                return 0f;
            }
            return item.getTasteLossStock().getNum();
        }).reduce(0f, Float::sum);
        DecimalFormat decimalFormat = new DecimalFormat(".000");
        String total = decimalFormat.format(sum);
        return Float.valueOf(total);
    }

    public Float getAllotInNum() {
        if (this.skuTotalSummaryDTOS == null || this.skuTotalSummaryDTOS.size() == 0) {
            return 0f;
        }
        Float sum = this.skuTotalSummaryDTOS.stream().map(item -> {
            if (item.getAllotInStock() == null) {
                return 0f;
            }
            return item.getAllotInStock().getNum();
        }).reduce(0f, Float::sum);
        DecimalFormat decimalFormat = new DecimalFormat(".000");
        String total = decimalFormat.format(sum);
        return Float.valueOf(total);
    }

    public Float getAllotOutNum() {
        if (this.skuTotalSummaryDTOS == null || this.skuTotalSummaryDTOS.size() == 0) {
            return 0f;
        }
        Float sum = this.skuTotalSummaryDTOS.stream().map(item -> {
            if (item.getAllotOutStock() == null) {
                return 0f;
            }
            return item.getAllotOutStock().getNum();
        }).reduce(0f, Float::sum);
        DecimalFormat decimalFormat = new DecimalFormat(".000");
        String total = decimalFormat.format(sum);
        return Float.valueOf(total);
    }

    public Float getOnlineNum() {
        if (this.skuTotalSummaryDTOS == null || this.skuTotalSummaryDTOS.size() == 0) {
            return 0f;
        }
        Float sum = this.skuTotalSummaryDTOS.stream().map(item -> {
            if (item.getOnlineStock() == null) {
                return 0f;
            }
            return item.getOnlineStock().getNum();
        }).reduce(0f, Float::sum);
        DecimalFormat decimalFormat = new DecimalFormat(".000");
        String total = decimalFormat.format(sum);
        return Float.valueOf(total);
    }

    public Float getOfflineNum() {
        if (this.skuTotalSummaryDTOS == null || this.skuTotalSummaryDTOS.size() == 0) {
            return 0f;
        }
        Float sum = this.skuTotalSummaryDTOS.stream().map(item -> {
            if (item.getOfflineStock() == null) {
                return 0f;
            }
            return item.getOfflineStock().getNum();
        }).reduce(0f, Float::sum);
        DecimalFormat decimalFormat = new DecimalFormat(".000");
        String total = decimalFormat.format(sum);
        return Float.valueOf(total);
    }

    public Float getReturnNum() {
        if (this.skuTotalSummaryDTOS == null || this.skuTotalSummaryDTOS.size() == 0) {
            return 0f;
        }
        Float sum = this.skuTotalSummaryDTOS.stream().map(item -> {
            if (item.getReturnStock() == null) {
                return 0f;
            }
            return item.getReturnStock().getNum();
        }).reduce(0f, Float::sum);
        DecimalFormat decimalFormat = new DecimalFormat(".000");
        String total = decimalFormat.format(sum);
        return Float.valueOf(total);
    }

    public Float getReturnSupplierNum() {
        if (this.skuTotalSummaryDTOS == null || this.skuTotalSummaryDTOS.size() == 0) {
            return 0f;
        }
        Float sum = this.skuTotalSummaryDTOS.stream().map(item -> {
            if (item.getReturnSupplierStock() == null) {
                return 0f;
            }
            return item.getReturnSupplierStock().getNum();
        }).reduce(0f, Float::sum);
        DecimalFormat decimalFormat = new DecimalFormat(".000");
        String total = decimalFormat.format(sum);
        return Float.valueOf(total);
    }

    public Float getStockCheckAddNum() {
        if (this.skuTotalSummaryDTOS == null || this.skuTotalSummaryDTOS.size() == 0) {
            return 0f;
        }
        Float sum = this.skuTotalSummaryDTOS.stream().map(item -> {
            if (item.getCheckAddStock() == null) {
                return 0f;
            }
            return item.getCheckAddStock().getNum();
        }).reduce(0f, Float::sum);
        DecimalFormat decimalFormat = new DecimalFormat(".000");
        String total = decimalFormat.format(sum);
        return Float.valueOf(total);
    }

    public Float getStockCheckSubNum() {
        if (this.skuTotalSummaryDTOS == null || this.skuTotalSummaryDTOS.size() == 0) {
            return 0f;
        }
        Float sum = this.skuTotalSummaryDTOS.stream().map(item -> {
            if (item.getCheckSubStock() == null) {
                return 0f;
            }
            return item.getCheckSubStock().getNum();
        }).reduce(0f, Float::sum);
        DecimalFormat decimalFormat = new DecimalFormat(".000");
        String total = decimalFormat.format(sum);
        return Float.valueOf(total);
    }


    public Float getStartStockPrice() {
        if (this.skuTotalSummaryDTOS == null || this.skuTotalSummaryDTOS.size() == 0) {
            return 0f;
        }
        Float sum = this.skuTotalSummaryDTOS.stream().map(item -> {
            if (item.getStartStock() == null) {
                return 0f;
            }
            return item.getStartStock().getTotalPrice();
        }).reduce(0f, Float::sum);
        DecimalFormat decimalFormat = new DecimalFormat(".00");
        String total = decimalFormat.format(sum);
        return Float.valueOf(total);
    }

    public Float getEndStockPrice() {
        if (this.skuTotalSummaryDTOS == null || this.skuTotalSummaryDTOS.size() == 0) {
            return 0f;
        }
        Float sum = this.skuTotalSummaryDTOS.stream().map(item -> {
            if (item.getEndStock() == null) {
                return 0f;
            }
            return item.getEndStock().getTotalPrice();
        }).reduce(0f, Float::sum);
        DecimalFormat decimalFormat = new DecimalFormat(".00");
        String total = decimalFormat.format(sum);
        return Float.valueOf(total);
    }

    public Float getInNumPrice() {
        if (this.skuTotalSummaryDTOS == null || this.skuTotalSummaryDTOS.size() == 0) {
            return 0f;
        }
        Float sum = this.skuTotalSummaryDTOS.stream().map(item -> {
            if (item.getPurchaseStock() == null) {
                return 0f;
            }
            return item.getPurchaseStock().getTotalPrice();
        }).reduce(0f, Float::sum);
        DecimalFormat decimalFormat = new DecimalFormat(".00");
        String total = decimalFormat.format(sum);
        return Float.valueOf(total);
    }

    public Float getOutNumPrice() {
        if (this.skuTotalSummaryDTOS == null || this.skuTotalSummaryDTOS.size() == 0) {
            return 0f;
        }
        Float sum = this.skuTotalSummaryDTOS.stream().map(item -> {
            if (item.getSalesSendStock() == null) {
                return 0f;
            }
            return item.getSalesSendStock().getTotalPrice();
        }).reduce(0f, Float::sum);
        DecimalFormat decimalFormat = new DecimalFormat(".00");
        String total = decimalFormat.format(sum);
        return Float.valueOf(total);
    }

    public Float getCommonLossNumPrice() {
        if (this.skuTotalSummaryDTOS == null || this.skuTotalSummaryDTOS.size() == 0) {
            return 0f;
        }
        Float sum = this.skuTotalSummaryDTOS.stream().map(item -> {
            if (item.getCommonLossStock() == null) {
                return 0f;
            }
            return item.getCommonLossStock().getTotalPrice();
        }).reduce(0f, Float::sum);
        DecimalFormat decimalFormat = new DecimalFormat(".00");
        String total = decimalFormat.format(sum);
        return Float.valueOf(total);
    }

    public Float getTasteLossNumPrice() {
        if (this.skuTotalSummaryDTOS == null || this.skuTotalSummaryDTOS.size() == 0) {
            return 0f;
        }
        Float sum = this.skuTotalSummaryDTOS.stream().map(item -> {
            if (item.getTasteLossStock() == null) {
                return 0f;
            }
            return item.getTasteLossStock().getTotalPrice();
        }).reduce(0f, Float::sum);
        DecimalFormat decimalFormat = new DecimalFormat(".00");
        String total = decimalFormat.format(sum);
        return Float.valueOf(total);
    }

    public Float getAllotInNumPrice() {
        if (this.skuTotalSummaryDTOS == null || this.skuTotalSummaryDTOS.size() == 0) {
            return 0f;
        }
        Float sum = this.skuTotalSummaryDTOS.stream().map(item -> {
            if (item.getAllotInStock() == null) {
                return 0f;
            }
            return item.getAllotInStock().getTotalPrice();
        }).reduce(0f, Float::sum);
        DecimalFormat decimalFormat = new DecimalFormat(".000");
        String total = decimalFormat.format(sum);
        return Float.valueOf(total);
    }

    public Float getAllotOutNumPrice() {
        if (this.skuTotalSummaryDTOS == null || this.skuTotalSummaryDTOS.size() == 0) {
            return 0f;
        }
        Float sum = this.skuTotalSummaryDTOS.stream().map(item -> {
            if (item.getAllotOutStock() == null) {
                return 0f;
            }
            return item.getAllotOutStock().getTotalPrice();
        }).reduce(0f, Float::sum);
        DecimalFormat decimalFormat = new DecimalFormat(".00");
        String total = decimalFormat.format(sum);
        return Float.valueOf(total);
    }

    public Float getOnlineNumPrice() {
        if (this.skuTotalSummaryDTOS == null || this.skuTotalSummaryDTOS.size() == 0) {
            return 0f;
        }
        Float sum = this.skuTotalSummaryDTOS.stream().map(item -> {
            if (item.getOnlineStock() == null) {
                return 0f;
            }
            return item.getOnlineStock().getNum();
        }).reduce(0f, Float::sum);
        DecimalFormat decimalFormat = new DecimalFormat(".00");
        String total = decimalFormat.format(sum);
        return Float.valueOf(total);
    }

    public Float getOfflineNumPrice() {
        if (this.skuTotalSummaryDTOS == null || this.skuTotalSummaryDTOS.size() == 0) {
            return 0f;
        }
        Float sum = this.skuTotalSummaryDTOS.stream().map(item -> {
            if (item.getOfflineStock() == null) {
                return 0f;
            }
            return item.getOfflineStock().getTotalPrice();
        }).reduce(0f, Float::sum);
        DecimalFormat decimalFormat = new DecimalFormat(".00");
        String total = decimalFormat.format(sum);
        return Float.valueOf(total);
    }

    public Float getReturnNumPrice() {
        if (this.skuTotalSummaryDTOS == null || this.skuTotalSummaryDTOS.size() == 0) {
            return 0f;
        }
        Float sum = this.skuTotalSummaryDTOS.stream().map(item -> {
            if (item.getReturnStock() == null) {
                return 0f;
            }
            return item.getReturnStock().getTotalPrice();
        }).reduce(0f, Float::sum);
        DecimalFormat decimalFormat = new DecimalFormat(".00");
        String total = decimalFormat.format(sum);
        return Float.valueOf(total);
    }

    public Float getReturnSupplierNumPrice() {
        if (this.skuTotalSummaryDTOS == null || this.skuTotalSummaryDTOS.size() == 0) {
            return 0f;
        }
        Float sum = this.skuTotalSummaryDTOS.stream().map(item -> {
            if (item.getReturnSupplierStock() == null) {
                return 0f;
            }
            return item.getReturnSupplierStock().getTotalPrice();
        }).reduce(0f, Float::sum);
        DecimalFormat decimalFormat = new DecimalFormat(".00");
        String total = decimalFormat.format(sum);
        return Float.valueOf(total);
    }

    public Float getStockCheckAddNumPrice() {
        if (this.skuTotalSummaryDTOS == null || this.skuTotalSummaryDTOS.size() == 0) {
            return 0f;
        }
        Float sum = this.skuTotalSummaryDTOS.stream().map(item -> {
            if (item.getCheckAddStock() == null) {
                return 0f;
            }
            return item.getCheckAddStock().getTotalPrice();
        }).reduce(0f, Float::sum);
        DecimalFormat decimalFormat = new DecimalFormat(".00");
        String total = decimalFormat.format(sum);
        return Float.valueOf(total);
    }

    public Float getStockCheckSubNumPrice() {
        if (this.skuTotalSummaryDTOS == null || this.skuTotalSummaryDTOS.size() == 0) {
            return 0f;
        }
        Float sum = this.skuTotalSummaryDTOS.stream().map(item -> {
            if (item.getCheckSubStock() == null) {
                return 0f;
            }
            return item.getCheckSubStock().getTotalPrice();
        }).reduce(0f, Float::sum);
        DecimalFormat decimalFormat = new DecimalFormat(".00");
        String total = decimalFormat.format(sum);
        return Float.valueOf(total);
    }
}
